package com.ycsj.goldmedalnewconcept.fragment;


import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import com.ycsj.goldmedalnewconcept.constant.ConfigConstant;
import com.ycsj.goldmedalnewconcept.gallery.GalleryFlow;
import com.ycsj.goldmedalnewconcept.gallery.ImageAdapter;
import com.ycsj.goldmedalnewconcept.utils.SPUtils;
import com.ycsj.goldmedalnewconcept.view.ImageCycleView;
import com.ycsj.goldmedalnewconcept.view.ImageCycleView.ImageCycleViewListener;
import com.ycsj.goldmedalnewconcept.R;

//微课堂
public class ClassFragment extends BaseFragment  {

	private static final String TAG = "ClassFragment";
	private Activity mActivity;
	private ArrayList<String> mData;
	private ImageCycleView words_arl;
	
	public static ClassFragment newInstance() {
		ClassFragment categoryFragment = new ClassFragment();
		
		return categoryFragment;
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		this.mActivity = activity;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}
	int[] gradeids=new int[]{3001,3002,3003,3004};
	String[] gradeNames=new String[]{"第一级","第二级","第三级","第四级"};
	@SuppressWarnings("deprecation")
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_grammar, container,
				false);
		SPUtils.put(getActivity(), ConfigConstant.CURRENTFRAGMENT, TAG);
		words_arl = (ImageCycleView) view.findViewById(R.id.words_arl);
//    	FrameLayout words_fragment_container = (FrameLayout) view.findViewById(R.id.words_fragment_container);
		
    	words_arl.setImageResources(getData() , mAdCycleViewListener);
//   	 final GalleryFlow cf = new GalleryFlow(getActivity());
//   	 GalleryFlow cf = (GalleryFlow) view.findViewById(R.id.Gallery01);
//   	 cf.setFadingEdgeLength(0);
//     cf.setSpacing(-100); //图片之间的间距
//   	 
//		cf.setAdapter(new ImageAdapter(getActivity(), imageIds));
//        cf.setAnimationDuration(1500);
////        words_fragment_container.addView(cf);
//        cf.setOnItemClickListener(new OnItemClickListener() {
//
//			@Override
//			public void onItemClick(AdapterView<?> parent, View view,
//					int position, long id) {
//				FragmentTransaction ft = getFragmentManager().beginTransaction();
//				GrammarSecondFragment gf = new GrammarSecondFragment();  
//	                Bundle args=new Bundle();
//	    			args.putInt("GRADE_ID", gradeids[position]);
//	    			gf.setArguments(args);
//	    			ft.replace(R.id.center_layout, gf);
//	    			ft.addToBackStack(null);
//	    			ft.commit();
//			}
//		});
//        cf.setSelection(1);
    	
    	ImageAdapter adapter = new ImageAdapter(getActivity(), imageIds);
        adapter.createReflectedImages();//创建倒影效果
        GalleryFlow galleryFlow = (GalleryFlow) view.findViewById(R.id.Gallery01);
        galleryFlow.setFadingEdgeLength(100);
        galleryFlow.setSpacing(-50); //图片之间的间距
        galleryFlow.setAdapter(adapter);
        galleryFlow.setSelection(0);
    	
        galleryFlow.setOnItemClickListener(new OnItemClickListener() {
        	//
        				@Override
        				public void onItemClick(AdapterView<?> parent, View view,
        						int position, long id) {
        					FragmentTransaction ft = getFragmentManager().beginTransaction();
        					ClassSecondFragment gf = new ClassSecondFragment();  
        		                Bundle args=new Bundle();
        		    			args.putInt("GRADE_ID", gradeids[position]);
        		    			args.putString("GRADE_NAME", gradeNames[position]);
        		    			gf.setArguments(args);
        		    			ft.replace(R.id.center_layout, gf);
        		    			ft.addToBackStack(null);
        		    			ft.commit();
        				}
        			});
        
        
		return view;
	}
	private Integer[] imageIds = new Integer[] {
			R.drawable.class01, 
			R.drawable.class02,
			R.drawable.class03,
			R.drawable.class04
};
	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		initViews(view);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
	}

	private void initViews(View view) {


	
	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

	
	

	

	@Override
	public String getFragmentName() {
		return TAG;
	}

	


	
	public ArrayList<String> getData() {
		mData = new ArrayList<String>();
		mData.add("http://139.129.57.83:8080/WebRes/AppRes/AppClass/WordLearning/Banner/banner-01.jpg");
		mData.add("http://139.129.57.83:8080/WebRes/AppRes/AppClass/WordLearning/Banner/banner-02.jpg");
		mData.add("http://139.129.57.83:8080/WebRes/AppRes/AppClass/WordLearning/Banner/banner-03.jpg");
		mData.add("http://139.129.57.83:8080/WebRes/AppRes/AppClass/WordLearning/Banner/banner-04.jpg");
//		mData.add("http://image.so.com/v?ie=utf-8&src=hao_360so&q=%E5%9B%BE%E7%89%87&fromurl=http%3A%2F%2Fwww.wz6.org%2Ffengjing%2F1609.html#multiple=1&dataindex=27&id=c68bb798b9652de1f529a96f90038ca9");
//		mData.add("http://image.so.com/v?ie=utf-8&src=hao_360so&q=%E5%9B%BE%E7%89%87&fromurl=http%3A%2F%2Fwww.wz6.org%2Ffengjing%2F1609.html#multiple=1&dataindex=27&id=c68bb798b9652de1f529a96f90038ca9");
//		mData.add("http://image.so.com/v?ie=utf-8&src=hao_360so&q=%E5%9B%BE%E7%89%87&fromurl=http%3A%2F%2Fwww.wz6.org%2Ffengjing%2F1609.html#multiple=1&dataindex=27&id=c68bb798b9652de1f529a96f90038ca9");
		
		return mData;
	}
	private ImageCycleViewListener mAdCycleViewListener = new ImageCycleViewListener() {
		@Override
		public void onImageClick(int position, View imageView) {
		}
	};

	
	
	
	
	
}
